package com.awenhui.demo.core.utils.poi;

import org.apache.poi.ss.usermodel.*;

/**
 * 单元个样式设置
 *  ExcelStyle style = new ExcelStyle(workbook);
 *  style.setAlignmentCenter().setHightlight().build();
 * @author yuxf
 * @version 1.0
 * @date 2020/7/23 12:23
 */
public class ExcelStyle {

    private CellStyle cellStyle;

    public ExcelStyle(Workbook workbook) {
        this.cellStyle = workbook.createCellStyle();
    }

    /**
     * 水平垂直居中
     *
     * @return
     */
    public ExcelStyle setAlignmentCenter() {
        cellStyle.setAlignment(HorizontalAlignment.CENTER);
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        return this;
    }

    /**
     * 高亮显示
     * @return
     */
    public ExcelStyle setHightlight()
    {
        cellStyle.setFillForegroundColor(IndexedColors.YELLOW.index);
        cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        return this;
    }
    /**
     * 绿色
     * @return
     */
    public ExcelStyle setSuccesColor()
    {
        cellStyle.setFillForegroundColor(IndexedColors.BRIGHT_GREEN.index);
        cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        return this;
    }
    /**
     * 红色
     * @return
     */
    public ExcelStyle setDangerColor()
    {
        cellStyle.setFillForegroundColor(IndexedColors.RED.index);
        cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        return this;
    }

    public CellStyle build() {
        return cellStyle;
    }

    public void test() {
        ExcelStyle style = new ExcelStyle(null);
        style.setAlignmentCenter().setHightlight().build();
    }

}
